package yxy.game.pm2.command.equip;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.BlacksmithMessage;
import yxy.game.pm2.message.PackageMessage;
import yxy.game.pm2.module.PackageHandle;

/** 工坊 装备合成界面 */
@MessageType(proto = Command.Equipement, classtype = BlacksmithMessage.EquipementRequest.class)
public class CMD_Equipement extends Command<BlacksmithMessage.EquipementRequest> {

	@Override
	public void execute(MessageSource messageSource, BlacksmithMessage.EquipementRequest request) {
		String playerCode = messageSource.getTag();

		BlacksmithMessage.EquipementResponse.Builder response = BlacksmithMessage.EquipementResponse.newBuilder();

		CurrencyType currencyType = CurrencyType.CT_装备;
		try {
			PackageMessage.Package.Builder pack = new PackageHandle().getPackage(playerCode, currencyType);
			response.setPack(pack);
			send(messageSource, response, Result.Success);
		} catch (Exception e) {
			send(messageSource, response, Result.DataError);
		}
	}

	private void send(MessageSource messageSource, BlacksmithMessage.EquipementResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}